home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / WIN / VB_TOOLS / FRMT_VB.ZIP / FORMATVB.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1992-12-09  |  31.4 KB  |  800 lines

  1. VERSION 2.00
  2. Begin Form FormFormatVB 
  3.    Caption         =   "Format VB Program"
  4.    Height          =   4360
  5.    Icon            =   FORMATVB.FRX:0000
  6.    Left            =   1485
  7.    LinkMode        =   1  'Source
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3480
  10.    ScaleWidth      =   6705
  11.    Top             =   1520
  12.    Width           =   6855
  13.    Begin CommandButton CommandClear 
  14.       Caption         =   "&Clear"
  15.       Height          =   620
  16.       Left            =   4560
  17.       TabIndex        =   5
  18.       Top             =   360
  19.       Width           =   855
  20.    End
  21.    Begin CommonDialog CMDialogFile 
  22.       Left            =   240
  23.       Top             =   2640
  24.    End
  25.    Begin TextBox TextBox 
  26.       Height          =   735
  27.       Index           =   1
  28.       Left            =   1800
  29.       MultiLine       =   -1  'True
  30.       TabIndex        =   1
  31.       Text            =   "Text1"
  32.       Top             =   1200
  33.       Width           =   4575
  34.    End
  35.    Begin CommandButton CommandQuit 
  36.       Caption         =   "&Quit"
  37.       Height          =   620
  38.       Left            =   5520
  39.       TabIndex        =   3
  40.       Top             =   360
  41.       Width           =   855
  42.    End
  43.    Begin CommandButton CommandProcess 
  44.       Caption         =   "&Process a Visual Basic File"
  45.       Height          =   620
  46.       Left            =   1800
  47.       TabIndex        =   0
  48.       Top             =   360
  49.       Width           =   2655
  50.    End
  51.    Begin PictureBox PictureIcon 
  52.       AutoRedraw      =   -1  'True
  53.       AutoSize        =   -1  'True
  54.       BorderStyle     =   0  'None
  55.       Height          =   640
  56.       Left            =   240
  57.       Picture         =   FORMATVB.FRX:0302
  58.       ScaleHeight     =   640
  59.       ScaleWidth      =   480
  60.       TabIndex        =   4
  61.       Top             =   240
  62.       Width           =   480
  63.    End
  64.    Begin Label LabelBox 
  65.       Alignment       =   1  'Right Justify
  66.       AutoSize        =   -1  'True
  67.       Caption         =   "LabelBox"
  68.       Height          =   195
  69.       Index           =   1
  70.       Left            =   840
  71.       TabIndex        =   2
  72.       Top             =   1200
  73.       Width           =   795
  74.    End
  75.    Begin Menu MenuOptions 
  76.       Caption         =   "&Options"
  77.       Begin Menu MenuDefaultPath 
  78.          Caption         =   "&Set Default Path"
  79.       End
  80.    End
  81.    Begin Menu MenuQuit 
  82.       Caption         =   "&Quit"
  83.    End
  84.    Begin Menu MenuHelp 
  85.       Caption         =   "&Help"
  86.       Begin Menu MenuHelpIndex 
  87.          Caption         =   "&Index"
  88.          Shortcut        =   {F1}
  89.       End
  90.       Begin Menu MenuHelpSep 
  91.          Caption         =   "-"
  92.       End
  93.       Begin Menu MenuHelpAbout 
  94.          Caption         =   "&About"
  95.       End
  96.    End
  97. ' FormatVB.Frm - Format VB .txt file
  98. ' 92/10/03 Copyright 1992, Larry Rebich, The Bridge, Inc.
  99. ' 92/10/04 Add Table of Contents
  100. ' 92/10/13 Use *.txt files
  101. ' 92/10/16 Fix problems with Left Margin and Tabs Expansion
  102. ' 92/12/01 Convert to VB 2.0, use .Frm files
  103. ' 92/12/07 Add Captions to Table of Contents
  104. ' 92/12/09 Add Help
  105. ' 92/12/09 Send a copy to Inside Visual Basic, Cobb Group
  106. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  107. DefInt A-Z                      'default data type is integer
  108. Const Version = "1.0"                   'version
  109. Const VersionDate = "December, 1992"    'version date, 92/12/09
  110. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  111. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  112. Const Pgm$ = "FormatVB Options" 'used in formatvb.ini file
  113. Const Which$ = "Default Path"   'used in formatvb.ini as well
  114. Const FileIni$ = "FormatVB.Ini" 'save default path name here, Windows Directory
  115. Const FormatVBHelpFile = "FormatVB.Hlp" 'help file name
  116. Const TempFName$ = "~ormatVB"   'temporary file name
  117. Const MaxSubs = 1500    'maximum number of sub, functions - increase if necessary
  118. Dim Recs$(1 To MaxSubs)         'store subs, functions here
  119. Dim RecCount As Integer         'number of records read
  120. Dim LFlag(1 To MaxSubs)         'flag, 0=normal text line
  121. '                                      1=Sub, Control_ [contains underline]
  122. '                                      3=Sub, Standard
  123. '                                      5=End Sub
  124. '                                      7=Function
  125. '                                      8=End Function
  126. Const xSub$ = "SUB"             'type 1 or 3
  127. Const xFun$ = "FUNCTION"        'type 7
  128. Const xEnd$ = "END"             'type 5 or 8
  129. Dim SortRec$(1 To MaxSubs)      'put sub/function records here
  130. Dim SortCt(1 To MaxSubs)        'and its record number
  131. Dim SortInSubCount(1 To MaxSubs)'and sub/function contains this many
  132. Dim SortLFlag(1 To MaxSubs)     'lflag here, type of sub/function
  133. Dim SortThisMany As Integer     'how many subs and functions
  134. Dim FirstSub As Integer         'first line containing sub or function
  135. Dim InFile As String            'input file name
  136. Dim OutFile As String           'output file
  137. Dim RandomFile As String        'store them here randomly
  138. Dim RandomRecSize As Integer    'random file record size
  139. Dim LongestLen As Integer       'Longest line length
  140. Dim LongestRec As Integer       'longest record number
  141. Dim GotInFile As Integer        'we have a file switch
  142. Dim PathName As String          'use this path name
  143. Dim InCmDialog As Integer       'in here now switch
  144. Dim VBFrmFile As Integer        'is it a VB 2.0 .frm file
  145. Dim SepLine As String           'separator line
  146. Dim AuthorIsUser As Integer     'is it the author
  147. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  148. Sub CommandClear_Click ()
  149.     For i = 1 To 3              'clear the text boxes
  150.     TextBox(i).Text = ""
  151.     Next
  152. End Sub
  153. Sub CommandProcess_Click ()
  154.     Screen.MousePointer = HourGlass     'tell 'em to wait
  155.     CommandProcess.Enabled = False      'dim this control
  156.     CommandQuit.Enabled = False         'dim this one as well
  157.     CommandClear.Enabled = False
  158.     MenuOptions.Enabled = False         'dim this menu items
  159.     MenuQuit.Enabled = False
  160.     MenuHelp.Enabled = False
  161.     PictureIcon.SetFocus                'so no focus on text box
  162.     CommandClear_Click                  'clear the text boxes
  163.     GetInFileName                       'get the file to process
  164.     If GotInFile = False Then GoTo ExitThis 'open failed, cancel pressed
  165.     Screen.MousePointer = HourGlass     'back on in case set off in Dialog
  166.     GetOutFileName                      'get output file name from input
  167.     GetRandomRecSize                    'get largest line size
  168.     GetFileRecords                      'read the input file
  169.     WriteJustSubAndFunRecords           'write a temporary file
  170.     SortEm                              'sort the subroutine and function names
  171.     PutFileRecords                      'build the output file
  172.     Beep                                'tell 'em we are done
  173.     Screen.MousePointer = Default       'back to normal
  174.     DeleteTemps                         'delete temporary files
  175. ExitThis:                               'if cancel pressed
  176.     CommandProcess.Enabled = True       'back on
  177.     CommandQuit.Enabled = True          'back on
  178.     CommandClear.Enabled = True
  179.     MenuOptions.Enabled = True
  180.     MenuQuit.Enabled = True
  181.     MenuHelp.Enabled = True
  182.     CommandProcess.SetFocus             'and light it
  183.     Screen.MousePointer = Default       'done waiting
  184. End Sub
  185. Sub CommandQuit_Click ()
  186.     FormatVBHelp Help_Quit, 0&  'dump help file if active
  187.     End                         'quit
  188. End Sub
  189. Sub DeleteTemps ()
  190.     Dim Temp As String
  191.     Temp = TempFName + ".*"     'temp file names to delete
  192. '    If AuthorIsUser Then        'for testing, delete the temps?
  193. '        Msg$ = "Delete temporary files? "
  194. '        MsgRtn% = MsgBox(Msg$, MB_YesNo + MB_IconQuestion, "Kill " + Temp)
  195. '        If MsgRtn% = IDNo Then Exit Sub     'said no, so don't delete
  196. '    End If
  197.     Kill PathName + Temp        'delete all temp files
  198. End Sub
  199. Sub DoTextBox3 (RecCountPut As Integer, TheRec As String, Force As Integer)
  200.     Dim RecNum As String
  201.     If RecCountPut Mod 9 = 0 Or Force Then      'only every 9 or forced
  202.     RecNum = Format$(RecCountPut, "####")   'record number
  203.     TextBox(3).Text = RecNum + " " + TheRec 'now into text box
  204.     End If
  205. End Sub
  206. Sub DumpSpecialCharacters (Rec As String)
  207. 'was needed for printer output, not needed for VB 2.0 Text Output
  208.     If VBFrmFile Then Exit Sub  'little faster
  209.     Dim Lf As String * 1        'line feed
  210.     Dim Cr As String * 1        'carriage return
  211.     Dim Ff As String * 1        'form feed
  212.     Dim x As String
  213.     Dim y As Integer
  214.     Lf = Chr$(10)
  215.     Cr = Chr$(13)
  216.     Ff = Chr$(12)
  217.     x = " " + Rec               'into x and add a blank
  218.     While InStr(x, Lf)          'dump line feeds
  219.     y = InStr(x, Lf)
  220.     x = Mid$(x, 1, y - 1) + Mid$(x, y + 1)
  221.     Wend
  222.     While InStr(x, Cr)          'dump carriage returns
  223.     y = InStr(x, Cr)
  224.     x = Mid$(x, 1, y - 1) + Mid$(x, y + 1)
  225.     Wend
  226.     While InStr(x, Ff)          'dump form feeds
  227.     y = InStr(x, Ff)
  228.     x = Mid$(x, 1, y - 1) + Mid$(x, y + 1)
  229.     Wend
  230.     Rec = Mid$(x, 2)            'dump blank that was added
  231. End Sub
  232. Sub ExpandTabs (Rec As String)
  233.     Static Lm As Integer                'previous left margin
  234.     Dim SkipLmSet As Integer            'skip resetting setting left margin
  235.     Dim t As String * 1                 'tab
  236.     Dim s As String                     'spacer
  237.     Dim x As String                     'work string
  238.     Dim ExtraChars As String            'based upon left margin
  239.     ExtraChars = ""                     'clear for now
  240.     t = Chr$(9)                         'tab character
  241.     SkipLmSet = False                   'switch, off if any tab
  242.     If Lm > 1 Then                      'if margin greater than this
  243.     If InStr(Rec, t) > 0 Then       'and if there is a tab
  244.         ExtraChars = String$(Lm - 1, " ")   'add some more characters
  245.         SkipLmSet = True            'and skip setting left margin
  246.     End If
  247.     End If
  248.     If InStr(Rec, t) > 0 Then           'any tab
  249.     Rec = ExtraChars + Rec          'add the extra characters to the record
  250.     End If
  251.     x = " " + Rec                       'one blank
  252.     CountTabs = 0                       'count tabs
  253.     While InStr(x, t) > 0               'expand the tabs
  254.     CountTabs = CountTabs + 1       'double second tab
  255.     If CountTabs = 1 Then
  256.         s = String$(4, " ")
  257.     Else
  258.         s = String$(8, " ")
  259.     End If
  260.     i = InStr(x, t)
  261.     x = Mid$(x, 1, i - 1) + s + Mid$(x, i + 1)
  262.     Wend
  263.     Rec = Mid$(x, 2)                    'dump extra blank
  264.     If CountTabs > 4 Then               'should not get here!!
  265.     Msg$ = "Found " + Format$(CountTabs, "##0") + " tabs in line:" + Str$(RecCount)
  266.     Msg$ = Msg$ + "  Record: |" + Rec + "|.  The line may not expand correctly."
  267.     MsgBox Msg$, MB_IconExclamation, "Too Many Tabs?"
  268.     End If
  269.     If SkipLmSet = False Then
  270.     x = Mid$(x, 2)                  'and work variable
  271.     x = RTrim$(x)                   'get number of leading blanks
  272.     sl = Len(x)                     'length before dumping leading blanks
  273.     x = LTrim$(x)                   'dump leading blanks
  274.     el = Len(x)                     'length without leading blanks
  275.     Lm = sl - el + 1                'left margin
  276.     End If
  277. End Sub
  278. Sub Form_Load ()
  279.     CenterForm Me, 0, 0                 'center on screen
  280.     GetPathFromIni                      'get default path from ini
  281.     SetColors                           'some color is nice
  282.     LoadBoxes                           'set control locations
  283.     SepLine = "'" + String$(78, "-") + "'"  'separates subs and functions
  284.     RandomFile = TempFName + ".rnd"     'temp random file name
  285.     x$ = Environ$("AUTHOR")             'is author the user
  286.     If UCase$(x$) = UCase$("LarryRebich") Then
  287.     AuthorIsUser = True             'environ has author's name
  288.     End If
  289.     Show                                'show 'em
  290.     Refresh                             'force display before asking for file
  291.     CommandProcess_Click                'start 'em off with file dialog
  292. End Sub
  293. Sub FormatVBHelp (WCmd%, dwData As Long)
  294.     Screen.MousePointer = HourGlass     'show 'em we are working
  295.     x% = WinHelp(hWnd, App.Path + FormatVBHelpFile, WCmd%, ByVal dwData)
  296.     Screen.MousePointer = Default       'done loading
  297. End Sub
  298. Sub GetFileRecords ()               'read the records
  299.     ReDim a$(1 To 200)              'array for parse
  300.     Dim Rec As String               'read ascii file into here
  301.     Dim Blanks As String            'bunch of blanks
  302.     Blanks = String$(RandomRecSize, " ")    'fill random file with recs and blanks
  303.     Erase LFlag                     'zeros into this array
  304.     RecCount = 0                    'record counter
  305.     f = FreeFile                    'file id
  306.     Open PathName + InFile For Input As #f
  307.     f2 = FreeFile                   'next file id
  308.     Open PathName + RandomFile For Output As #f2 'work with a new one
  309.     Close #f2
  310.     Kill PathName + RandomFile      'dump the one just opened
  311.     Open PathName + RandomFile For Random As #f2 Len = RandomRecSize + 2
  312.     FirstSub = 0                    'this will contain the rec number of the first sub
  313.     While Not EOF(f)                'read until end of file
  314.     Line Input #f, Rec              'read the record
  315.     DumpSpecialCharacters Rec       'get rid of special characters
  316.     x$ = Trim$(Rec)                 'don't process completely blank records
  317.     If x$ <> "" Then
  318.         RecCount = RecCount + 1     'bump record counter
  319.         ExpandTabs Rec
  320.         Rec = Left$(Rec + Blanks, RandomRecSize)    'add blanks to pad record
  321.         Put #f2, RecCount, Rec          'store in random file
  322.         x$ = UCase$(LTrim$(Rec))        'work with it to see if Sub, End, etc.
  323.         If Left$(x$, 1) <> "'" Then     'if starts with comment then skip
  324.         anum = Parse(x$, a$(), " ") 'split apart
  325.         Select Case a$(1)           'first
  326.             Case xSub$              'sub
  327.             GoSub IfFirstSubFun 'is it the first one
  328.             If InStr(a$(2), "_") > 0 Then
  329.                 LFlag(RecCount) = 1     'command_event
  330.             Else
  331.                 LFlag(RecCount) = 3     'standard sub
  332.             End If
  333.             Recs(RecCount) = Rec        'store subs into matrix
  334.             TextBox(2).Text = " " + Rec
  335.             Case xFun$              'function
  336.             GoSub IfFirstSubFun
  337.             LFlag(RecCount) = 7
  338.             Recs(RecCount) = Rec
  339.             TextBox(2).Text = " " + Rec
  340.             Case xEnd$
  341.             Select Case a$(2)
  342.                 Case xSub$      'end sub
  343.                 LFlag(RecCount) = 5
  344.                 Case xFun$      'end function
  345.                 LFlag(RecCount) = 8
  346.             End Select
  347.             Case Else               'nothing special
  348.             LFlag(RecCount) = 0
  349.             DoTextBox3 RecCount, LTrim$(Rec), False
  350.             Refresh
  351.         End Select
  352.         Else
  353.         DoTextBox3 RecCount, LTrim$(Rec), False
  354.         End If
  355.     End If
  356.     Wend
  357.     DoTextBox3 RecCount, LTrim$(Rec), True    'in case not shown
  358.     Close #f, #f2       'done with input and done creating random file
  359.     Reset
  360.     'in case there were no subs or functions [constant.txt!]
  361.     If FirstSub = 0 Then FirstSub = RecCount + 1
  362.     Exit Sub
  363. IfFirstSubFun:
  364.     If FirstSub = 0 Then FirstSub = RecCount    'first sub record number
  365.     Return
  366. End Sub
  367. Sub GetInFileName ()
  368.     Dim Fltr As String, f As Integer, Rec1 As String
  369.     InCmDialog = True                   'get file to process
  370.     CmDialogFile.DefaultExt = ".frm"    'default extension
  371.     CmDialogFile.DialogTitle = "VB Input File"
  372.     CmDialogFile.Filename = "*.frm"
  373.     Fltr = ""
  374.     Fltr = Fltr & "VB Forms [*.frm]|*.frm|"     'for VB 2.0 92/12/01
  375.     Fltr = Fltr & "Bas Files [*.bas]|*.bas|"
  376.     Fltr = Fltr & "Sub Files [*.sub]|*.sub|"
  377.     Fltr = Fltr & "Glb Files [*.glb]|*.glb|"
  378.     Fltr = Fltr & "Txt Files [*.txt]|*.txt|"
  379.     Fltr = Fltr & "Prn Files [*.prn]|*.prn|"
  380.     Fltr = Fltr & "All Files [*.*]|*.*|"
  381.     CmDialogFile.Filter = Fltr
  382.     CmDialogFile.Flags = OFN_READONLY Or OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST
  383.     CmDialogFile.CancelError = True     'allow cancel key to cause error
  384.     CmDialogFile.InitDir = PathName
  385.     GotInFile = True                    'say we got one
  386.     On Error Resume Next                'in case cancel pressed
  387.     CmDialogFile.Action = DLG_FILE_OPEN 'do it
  388.     If Err = 0 Then                     'ok, got name
  389.     InFile = CmDialogFile.Filetitle
  390.     PathName = CmDialogFile.Filename
  391.     PathName = Mid$(PathName, 1, InStr(PathName, InFile) - 1)
  392.     If Right$(PathName, 1) <> "\" Then
  393.         PathName = PathName + "\"
  394.     End If
  395.     If InStr(LCase$(InFile), ".frm") > 0 Then 'VB 2.0
  396.         f = FreeFile                'check to see if it is valid
  397.         Open PathName & InFile For Input As #f
  398.         Line Input #f, Rec1
  399.         Rec1 = Trim$(Rec1)
  400.         If Rec1 <> "VERSION 2.00" Then
  401.         GotInFile = False
  402.         Beep
  403.         TextBox(1).Text = "  " + LCase$(PathName + InFile) + " - Not a VB 2.0 File"
  404.         Else
  405.         GoSub PathAndIniUpdate
  406.         VBFrmFile = True        'it is a VB .frm file
  407.         End If
  408.     Else                            'not VB 2.0
  409.         GoSub PathAndIniUpdate
  410.         VBFrmFile = False           'not VB .frm file
  411.     End If
  412.     ElseIf Err = 32755 Then             'cancel pressed
  413.     GotInFile = False
  414.     End If
  415.     InCmDialog = False                  'done with this process
  416.     Exit Sub
  417. PathAndIniUpdate:                       'ok, store it
  418.     UpdateIni PathName                  'store it
  419.     TextBox(1).Text = "  " + LCase$(PathName + InFile) + " - Input"
  420.     Return
  421. End Sub
  422. Sub GetOutFileName ()                   'get OutFile from InFile
  423.     Dim x As String
  424.     If InStr(InFile, ".") > 0 Then      'find period
  425.     x = Mid$(InFile, 1, InStr(InFile, ".") - 1)
  426.     OutFile = x + ".wrk"
  427.     Else
  428.     OutFile = "FormatVB.Wrk"        'should not get here
  429.     End If
  430. End Sub
  431. Sub GetPathFromIni ()
  432.     Dim Buf As Integer, Value As String, Num As Integer
  433.     Buf = 64                            'read the .ini file
  434.     Value = Space$(Buf)
  435.     Num = GetPrivateProfileString(Pgm$, Which, "", Value, Buf, FileIni)
  436.     If Num > 0 Then
  437.     PathName = Trim$(Mid$(Value, 1, Num))
  438.     Else
  439.     PathName = ""                   'no .ini value found
  440.     End If
  441.     TextBox(1).Text = "  " + PathName   'display it
  442. End Sub
  443. Sub GetRandomRecSize ()
  444. 'get the longest line, needed to set the random record length
  445.     Dim x As String
  446.     Dim z As Integer
  447.     f = FreeFile                            'get the largest line number
  448.     Open PathName + InFile For Input As #f
  449.     While Not EOF(f)
  450.     Line Input #f, x                    'read line
  451.     DumpSpecialCharacters x             'drop special characters
  452.     ExpandTabs x                        'expand it
  453.     x = RTrim$(x)                       'dump any trailing blanks
  454.     z = Len(x)                          'size of remaining record
  455.     If RandomRecSize < z Then           'if x longer then use save it
  456.         RandomRecSize = z               'use it
  457.     End If
  458.     Wend
  459.     Close #f                                'done, close it
  460. End Sub
  461. Sub LoadBoxes ()
  462.     Static HereBefore As Integer        'set up the screen
  463.     Of = 100
  464.     If HereBefore = False Then          'do this just once
  465.     HereBefore = True
  466.     For i = 2 To 3
  467.         Load LabelBox(i)            'load the extra labels and boxes
  468.         LabelBox(i).Visible = True
  469.         Load TextBox(i)
  470.         TextBox(i).Visible = True
  471.     Next
  472.     For i = 1 To 3
  473.         If i < 3 Then
  474.         TextBox(i).Height = CommandProcess.Height * .75
  475.         Else
  476.         TextBox(i).Height = CommandProcess.Height * 1.5
  477.         TBLeft = TextBox(i).Width * .35
  478.         TextBox(i).Width = TextBox(1).Width + TBLeft
  479.         End If
  480.     Next
  481.     End If
  482.     TextBox(1).Top = CommandProcess.Top + CommandProcess.Height + Of * 2
  483.     TextBox(1).Left = CommandProcess.Left
  484.     TextBox(2).Left = TextBox(1).Left
  485.     TextBox(3).Left = TextBox(1).Left - TBLeft
  486.     TextBox(2).Top = TextBox(1).Top + TextBox(1).Height + Of
  487.     TextBox(3).Top = TextBox(2).Top + TextBox(1).Height + Of
  488.     LabelBox(1).Caption = "File"
  489.     LabelBox(2).Caption = "Routine"
  490.     LabelBox(3).Caption = "Line"
  491.     For i = 1 To 3
  492.     If i > 1 Then
  493.         TextBox(i).Text = ""
  494.     End If
  495.     LabelBox(i).Top = TextBox(i).Top + Of
  496.     LabelBox(i).Left = TextBox(i).Left - LabelBox(i).Width - Of * 2
  497.     If i = 3 Then
  498.         LabelBox(i).Left = LabelBox(i).Left - TBLeft
  499.     End If
  500.     LabelBox(i).BackColor = BackColor
  501.     LabelBox(i).ForeColor = ForeColor
  502.     Next
  503. End Sub
  504. Sub MenuDefaultPath_Click ()
  505. 'allow a default path name to be entered
  506.     P$ = "Enter a default path name, or press enter to retain the current path."
  507.     t$ = "Default Path"
  508. TryAgain:
  509.     Value$ = InputBox$(P$, t$, PathName)
  510.     If Value$ = PathName Then Exit Sub  'no change
  511.     If Value$ = "" Then Exit Sub        'cancel pressed
  512.     If Right$(Value$, 1) <> "\" Then    'add ending \ if needed
  513.     Value$ = Value$ + "\"
  514.     End If
  515.     On Error GoTo BadDir                'if no file or bad name
  516.     x$ = Dir$(Value$ + "*.*")           'get any file
  517.     If x$ = "" Then                     'any file in directory?
  518.     Msg$ = "No files in directory: " + Value$
  519.     MsgBox Msg$, MB_IconExclamation, "Invalid Directory"
  520.     GoTo TryAgain
  521.     End If
  522.     PathName = Value$                   'store the new value
  523.     TextBox(1).Text = "  " + PathName   'into text box to display it
  524.     UpdateIni Value$                    'update the .ini file
  525.     Exit Sub
  526. BadDir:
  527.     MsgBox Error$, MB_IconExclamation, "Failed to Find Any Files"
  528.     Resume TryAgain
  529. End Sub
  530. Sub MenuHelpAbout_Click ()
  531.     Dim Msg As String, Nl As String * 2     'some info about the author
  532.     Dim Sp As String                        'some spaces
  533.     Sp = String$(9, " ")
  534.     Nl = Chr$(13) + Chr$(10)
  535.     Msg = "FormatVB - Format Visual Basic Text" + Nl
  536.     Msg = Msg + "Version: " + Version + " " + VersionDate + Nl + Nl
  537.     Msg = Msg + Sp + "Copyright " + Format$(Now, "yyyy") + Nl + Nl
  538.     Msg = Msg + Sp + "Larry Rebich" + Nl
  539.     Msg = Msg + Sp + "The Bridge, Inc." + Nl
  540.     Msg = Msg + Sp + "199 California Drive" + Nl
  541.     Msg = Msg + Sp + "Millbrae, CA  94030" + Nl + Nl
  542.     Msg = Msg + Sp + "415-697-2730" + Nl
  543.     Msg = Msg + Sp + "Fax: 415-692-3921"
  544.     MsgBox Msg, MB_IconQuestion, "About FormatVB"
  545. End Sub
  546. Sub MenuHelpIndex_Click ()
  547.     FormatVBHelp Help_Context, 10&  'help requested
  548. End Sub
  549. Sub MenuQuit_Click ()
  550.     CommandQuit_Click               'end it
  551. End Sub
  552. Sub PrintSepLine (f As Integer)
  553.     PrintSub f, SepLine, 0      'print a separator line
  554. End Sub
  555. Sub PrintSub (f As Integer, PLine As String, LineNumber As Integer)
  556. ' common print subroutine
  557.     Static HoldLine As String
  558.     If HoldLine = SepLine And PLine = SepLine Then  'no two sep together
  559.     Exit Sub
  560.     End If
  561.     HoldLine = PLine
  562.     Dim Counter As String
  563.     If LineNumber > 0 Then              'print line number, unless zero
  564.     Counter = Right$("    " + Format$(LineNumber, "####"), 4)
  565.     Print #f, Counter; " "; PLine
  566.     If Len(PLine) > LongestLen Then
  567.         LongestRec = LineNumber     'new value
  568.         LongestLen = Len(PLine)     'and save for compare
  569.     End If
  570.     Else
  571.     Print #f, PLine     'don't count this line, usually a separator
  572.     End If
  573. End Sub
  574. Sub PutFileRecords ()
  575. ' write them to the .wrk file now, almost done
  576.     Dim HaveBeginSw As Integer, HaveEndSw As Integer
  577.     LongestRec = 0                      'reset this
  578.     LongestLen = 0                      'and this
  579.     RecCountPut = 0                     'record counter
  580.     CommentStringLen = 40
  581.     CommentString$ = String$(CommentStringLen, "'")
  582.     TextBox(1).Text = " " + LCase$(PathName + OutFile) + " - Output"
  583.     f = FreeFile
  584.     Open PathName + OutFile For Output As #f
  585.     f2 = FreeFile                       'random file
  586.     Open PathName + RandomFile For Random As #f2 Len = RandomRecSize + 2
  587.     If SortThisMany >= 1 Then
  588.     PutTableOfContents f, f2        'do the table of contents
  589.     PrintSepLine f
  590.     End If
  591.     If FirstSub > 1 Then                'any general
  592.     For j = 1 To FirstSub - 1       'general info
  593.         GoSub WriteRec
  594.         DoTextBox3 RecCountPut, x$, False
  595.     Next
  596.     PrintSepLine f
  597.     End If
  598.     For i = 1 To SortThisMany           'do Command_Click type first
  599.     If SortLFlag(i) = 1 Then
  600.         For j = SortCt(i) To SortCt(i) + SortInSubCount(i) - 1
  601.         GoSub WriteRec
  602.         GoSub IntoTextBox
  603.         Next
  604.         PrintSepLine f
  605.     End If
  606.     Next
  607.     For i = 1 To SortThisMany           'do normal subs next
  608.     If SortLFlag(i) = 3 Then
  609.         For j = SortCt(i) To SortCt(i) + SortInSubCount(i) - 1
  610.         GoSub WriteRec
  611.         GoSub IntoTextBox
  612.         Next
  613.         PrintSepLine f
  614.     End If
  615.     Next
  616.     For i = 1 To SortThisMany           'do functions next
  617.     If SortLFlag(i) = 7 Then
  618.         For j = SortCt(i) To SortCt(i) + SortInSubCount(i) - 1
  619.         GoSub WriteRec
  620.         GoSub IntoTextBox
  621.         Next
  622.         PrintSepLine f
  623.     End If
  624.     Next
  625.     'wrap up
  626.     x$ = String$(4, " ")
  627.     m$ = "####"
  628.     PrintSub f, Right$(x$ + Format$(RecCountPut, m$), 4) + " lines in file " + LCase$(PathName + OutFile), 0
  629.     PrintSub f, Right$(x$ + Format$(LongestLen, m$), 4) + " characters in longest line", 0
  630.     PrintSub f, Right$(x$ + Format$(LongestRec, m$), 4) + " first longest line", 0
  631.     Close                           'close any open files
  632.     Reset                           'force buffers to disk
  633.     Exit Sub
  634. WriteRec:                           'write the temp file
  635.     RecCountPut = RecCountPut + 1
  636.     Get #f2, j, x$
  637.     x$ = RTrim$(x$)
  638.     y$ = LTrim$(x$)                 'dump long strings with only '''''
  639.     If Left$(y$, CommentStringLen) <> CommentString$ Then
  640.     PrintSub f, x$, RecCountPut
  641.     If VBFrmFile Then               'is this a VB 2.0 form
  642.         If HaveEndSw = False Then   'only do this once
  643.         If HaveBeginSw = False Then
  644.             If Left$(LCase$(x$), 5) = "begin" Then
  645.             HaveBeginSw = True
  646.             End If
  647.         Else
  648.             If Left$(LCase$(x$), 3) = "end" Then
  649.             HaveEndSw = True
  650.             PrintSepLine f  'separator after last end
  651.             End If
  652.         End If
  653.         End If
  654.     End If
  655.     End If
  656.     Return
  657. IntoTextBox:                        'show record in text box
  658.     If j = SortCt(i) Then           'sub or function name
  659.     TextBox(2).Text = " " + x$
  660.     Else                            'just an ordinary record
  661.     DoTextBox3 RecCountPut, LTrim$(x$), True
  662.     End If
  663.     Return
  664. End Sub
  665. Sub PutTableOfContents (f As Integer, f2 As Integer)
  666. 'write the table of contents to the .wrk file
  667.     Dim Toc As String                   'sub into here
  668.     Dim LToc As String                  'local
  669.     Dim HoldFlag As Integer             'extra line on type break
  670.     ReDim SecType(1 To 7) As String     'section names stored here
  671.     Dim SecLen As Integer               'store section len here
  672.     SecType(1) = "     Controls    "    'section headings
  673.     SecType(3) = "     Subroutines "
  674.     SecType(7) = "     Functions   "
  675.     SecLen = Len(SecType(1))            'longest one
  676.     f9 = FreeFile                       'work file
  677.     TocOffset = SecLen                  'TOC offset
  678.     ReDim AToc(1 To 500) As String
  679.     Open PathName + TempFName + ".toc" For Output As #f9
  680.     StartLine = FirstSub                'first subroutine line number
  681.     For i = 1 To SortThisMany           'this many to put in Toc
  682.     Get #f2, SortCt(i), Toc         'get the sub
  683.     Toc = LTrim$(RTrim$(Toc))
  684.     aTocNum = Parse(Toc, AToc(), " ")'just sub and name
  685.     LToc = Left$(AToc(1) + " " + AToc(2) + String$(40, "."), 40)
  686.     LToc = String$(TocOffset, " ") + LToc + Right$("....." + Format$(StartLine, "####"), 4)
  687.     LToc = SecType(SortLFlag(i)) + Mid$(LToc, TocOffset)    'add caption
  688.     SecType(SortLFlag(i)) = String$(SecLen, " ")'kill it after first one
  689.     If i > 1 Then                   'not first time
  690.         If HoldFlag <> SortLFlag(i) Then    'extra line on Flag break
  691.         HoldFlag = SortLFlag(i)
  692.         Print #f9, ""           'blank line between types
  693.         Print #f, ""
  694.         End If
  695.     Else
  696.         HoldFlag = SortLFlag(i)     'first time, set hold flag
  697.     End If
  698.     Print #f9, LToc                 'work file
  699.     Print #f, LToc                  'real file
  700.     StartLine = StartLine + SortInSubCount(i)
  701.     Next
  702.     Print #f, ""                        'extra line after TOC
  703.     Close #f9                           'close temp file
  704. End Sub
  705. Sub SetColors ()
  706.     BackColor = Application_Workspace   'some color is nice
  707.     ForeColor = Window_Text
  708. End Sub
  709. Sub SortEm ()
  710.     Erase SortInSubCount            'clear the arrays
  711.     Erase SortRec
  712.     Erase SortCt
  713.     SortThisMany = 0
  714.     For i = 1 To RecCount
  715.     Select Case LFlag(i)        'build sort array
  716.         Case 1, 3, 7            'sub or function
  717.         SortThisMany = SortThisMany + 1
  718.         ReDim RecArray$(1 To 500)
  719.         x$ = Recs(i)            'into unindexed string
  720.         RecArrayNumber = Parse(x$, RecArray$(), " ")
  721.         x$ = RecArray$(1) + " " + RecArray$(2)
  722.         SortRec(SortThisMany) = x$  'the sub, function
  723.         SortCt(SortThisMany) = i    'record number
  724.         SortLFlag(SortThisMany) = LFlag(i)
  725.         SortInSubCount(SortThisMany) = SortInSubCount(SortThisMany) + 1
  726.         Case Else               'all other types
  727.         If SortThisMany > 0 Then    'count records in sub or function
  728.             SortInSubCount(SortThisMany) = SortInSubCount(SortThisMany) + 1
  729.         End If
  730.     End Select
  731.     Next
  732.     WriteEm PathName + TempFName + ".nrt"   'write unsorted temp file for debug
  733.     For i = 1 To SortThisMany - 1   'sort decending by name, end up ascending
  734.     For j = i + 1 To SortThisMany
  735.         If SortRec(i) < SortRec(j) Then     'swap them
  736.         SortSwap i, j
  737.         End If
  738.     Next
  739.     Next
  740.     WriteEm PathName + TempFName + ".srt"   'write sort by name for debug
  741.     For i = 1 To SortThisMany - 1   'sort by type, end up ascending
  742.     For j = i + 1 To SortThisMany
  743.         If SortLFlag(i) >= SortLFlag(j) Then 'swap them
  744.         SortSwap i, j
  745.         End If
  746.     Next
  747.     Next
  748.     WriteEm PathName + TempFName + ".typ"   'write final sort for debug
  749. End Sub
  750. Sub SortSwap (i As Integer, j As Integer)
  751.     Dim Tmp As String, TmpCt As Integer
  752.     Tmp = SortRec(i)                'swap sort array elements
  753.     SortRec(i) = SortRec(j)
  754.     SortRec(j) = Tmp
  755.     TmpCt = SortCt(i)
  756.     SortCt(i) = SortCt(j)
  757.     SortCt(j) = TmpCt
  758.     TmpCt = SortInSubCount(i)
  759.     SortInSubCount(i) = SortInSubCount(j)
  760.     SortInSubCount(j) = TmpCt
  761.     TmpCt = SortLFlag(i)
  762.     SortLFlag(i) = SortLFlag(j)
  763.     SortLFlag(j) = TmpCt
  764. End Sub
  765. Sub TextBox_GotFocus (Index As Integer)
  766.     If InCmDialog = True Then Exit Sub  'can't set focus while showing another screen
  767.     CommandProcess.SetFocus             'don't allow focus on the text boxes
  768. End Sub
  769. Sub UpdateIni (Value As String)
  770.     Dim Result As Integer           'update the .ini file
  771.     Result = WritePrivateProfileString(Pgm$, Which$, LCase$(Value$), FileIni$)
  772.     If Result = 0 Then              'should not get an error
  773.     Msg$ = "Could not update " + UCase$(Which$) + "=" + UCase$(Value$) + " in File: " + UCase$(FileIni$)
  774.     MsgBox Msg$, MB_IconExclamation, "Update INI Error"
  775.     End If
  776. End Sub
  777. Sub WriteEm (WFile As String)
  778.     Dim x1 As String, x2 As String, x3 As String
  779.     f = FreeFile                'write temporary files, for debug
  780.     Open WFile For Output As #f
  781.     For i = 1 To SortThisMany
  782.     x1 = Right$("    " + Trim$(Str$(SortCt(i))), 4)  'starting number
  783.     x2 = Right$("    " + Trim$(Str$(SortInSubCount(i))), 4)  'records in sub
  784.     x3 = Right$(" " + Trim$(Str$(SortLFlag(i))), 1)   'type
  785.     Print #f, x1; " "; x2; " "; x3; " "; SortRec(i)
  786.     Next
  787.     Close #f
  788. End Sub
  789. Sub WriteJustSubAndFunRecords ()
  790.     f = FreeFile                        'temporary file
  791.     Open PathName + TempFName + ".lst" For Output As #f
  792.     For i = 1 To RecCount
  793.     If Len(Recs(i)) > 0 Then
  794.         Print #f, FirstSub; " "; LFlag(i); " "; Recs(i)
  795.     End If
  796.     Next
  797.     Close #f
  798.     Reset
  799. End Sub
  800.